<script setup>
import { ref, reactive } from 'vue'
import { useRouter } from 'vue-router'
import { ElForm, ElFormItem, ElInput, ElButton, ElMessage, ElCard, ElDivider } from 'element-plus'

const router = useRouter()
const form = reactive({
  username: '',
  password: ''
})

const rules = {
  username: [
    { required: true, message: '请输入用户名', trigger: 'blur' }
  ],
  password: [
    { required: true, message: '请输入密码', trigger: 'blur' }
  ]
}

const handleLogin = () => {
  // 简单的登录验证（实际项目中应该调用API）
  if (form.username === 'admin' && form.password === 'password') {
    localStorage.setItem('isLoggedIn', 'true')
    localStorage.setItem('username', form.username)
    ElMessage.success('登录成功')
    router.push('/home')
  } else {
    ElMessage.error('用户名或密码错误')
  }
}
</script>

<template>
  <div class="login-container">
    <el-card class="login-card" shadow="hover">
      <template #header>
        <div class="login-header">
          <h2>登录系统</h2>
        </div>
      </template>
      
      <el-form :model="form" :rules="rules" label-width="80px" class="login-form">
        <el-form-item label="用户名" prop="username">
          <el-input
            v-model="form.username"
            placeholder="请输入用户名"
            prefix-icon="el-icon-user"
            autocomplete="username"
          />
        </el-form-item>
        
        <el-form-item label="密码" prop="password">
          <el-input
            v-model="form.password"
            type="password"
            placeholder="请输入密码"
            prefix-icon="el-icon-lock"
            autocomplete="current-password"
          />
        </el-form-item>
        
        <el-form-item>
          <el-button 
            type="primary" 
            @click="handleLogin" 
            class="login-button"
            :loading="false"
          >
            登录
          </el-button>
        </el-form-item>
      </el-form>
      
      <el-divider>测试账号信息</el-divider>
      <div class="login-tips">
        <el-descriptions :column="2" border>
          <el-descriptions-item label="测试账号">admin</el-descriptions-item>
          <el-descriptions-item label="测试密码">password</el-descriptions-item>
        </el-descriptions>
      </div>
    </el-card>
  </div>
</template>

<style scoped>
.login-container {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 100vh;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  padding: 20px;
}

.login-card {
  width: 100%;
  max-width: 450px;
}

.login-header {
  text-align: center;
}

.login-form {
  margin-top: 20px;
}

.login-button {
  width: 100%;
  font-size: 16px;
  padding: 12px 0;
}

.login-tips {
  margin-top: 20px;
}
</style>